import { nodeResolve } from '@rollup/plugin-node-resolve'
import type { UserConfig } from 'vite'
import { defineConfig } from 'vite'
import dts from 'vite-plugin-dts'

export default defineConfig((config: UserConfig) => {
  return {
    publicDir: false,
    clearScreen: false,
    plugins: [
      dts({
        // 自动复制d.ts
        copyDtsFiles: true,
        insertTypesEntry: true,
        outDir: 'dist/dts',
        include: ['./src', './index.ts'],
      }),
    ],
    build: {
      outDir: 'dist',
      minify: 'terser',
      assetsInlineLimit: 1024 * 100, // 小于100kb的静态资源打包时将内联为base64
      lib: {
        entry: './index.ts',
        name: 'fetm-utils',
        formats: ['es'],
      },
      rollupOptions: {
        // 第三方库/样式取消打包, 在peerDependencies中加入了该依赖, 会自动引入
        external: [
          'axios',
          'dayjs',
          'element-plus',
          'lodash-es',
          'qs',
          'crypto-js',
          'xlsx',
          'dom-to-image-more',
          'docxtemplater',
          'pizzip',
          'docxtemplater-image-module-free',
          'croner',
          'idb',
        ],
        output: {
          exports: 'named',
        },
        plugins: [nodeResolve()],
      },
    },
  } as UserConfig
})
